<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 * @author   howe <howe1995@163.com>
 */
use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

return new class() extends Migration {
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('friends', function (Blueprint $table) {
            $table->id();
            $table->integer('owner')->unsigned()->default(0)->comment('用户ID');
            $table->integer('friend')->unsigned()->default(0)->comment('好友ID');
            $table->string('nickname')->default('')->comment('好友昵称');
            $table->enum('type', ['apply', 'verify'])->default('apply')->comment('好友类型');
            $table->enum('status', ['check', 'pass', 'overdue'])->default('check')->comment('好友状态');
            $table->tinyInteger('is_read')->unsigned()->default(0)->comment('是否已读');
            $table->integer('unread')->unsigned()->default(0)->comment('未读消息数');
            $table->integer('top')->unsigned()->default(0)->comment('置顶时间');
            $table->text('content')->nullable()->comment('最新消息');
            $table->integer('time')->unsigned()->default(0)->comment('最新消息时间');
            $table->tinyInteger('display')->unsigned()->default(0)->comment('是否显示');
            $table->tinyInteger('hide')->unsigned()->default(0)->comment('是否隐藏');
            $table->tinyInteger('muted')->unsigned()->default(0)->comment('是否免打扰');
            $table->integer('bg_file_id')->unsigned()->default(0)->comment('背景图ID(对应files里的ID)');
            $table->string('bg_file_path')->default('')->comment('背景图路径');
            $table->string('remark')->default('')->comment('好友备注');
            $table->string('desc')->default('')->comment('好友描述');
            $table->json('setting');
            $table->enum('source', ['mobile', 'wechat', 'group', 'qrcode', 'assistant'])->default('mobile')->comment('好友来源');
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('deleted_at')->nullable()->default(null);
            $table->timestamp('updated_at')->useCurrent();
            $table->unique(['owner', 'friend'], 'uk_owner_friend', 'BTREE');
            $table->comment('好友表');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('friends');
    }
};
